import { ModalForm, ProFormTextArea } from '@ant-design/pro-components';
import { message } from 'antd';
import { updateFailureReport } from '../service';

const HandleReport = (props: {
  visible: boolean;
  setUnvisible: () => void;
  reload: () => void;
  id: string;
}) => {
  const { visible, setUnvisible, reload, id } = props;
  return (
    <ModalForm
      title="故障处理"
      layout="horizontal"
      width="40vw"
      modalProps={{
        destroyOnClose: true,
        onCancel: () => {
          setUnvisible();
        },
      }}
      labelCol={{ span: 6 }}
      wrapperCol={{ span: 14 }}
      visible={visible}
      onFinish={async (values) => {
        const res = await updateFailureReport({
          id,
          remark: values.remark || '',
        });
        if (res.success) {
          message.success({ content: res.message, key: 'handle_report' });
          reload();
          setUnvisible();
          return true;
        }
        message.error({ content: res.message, key: 'handle_report' });
        return false;
      }}
    >
      <ProFormTextArea name="remark" required label="处理结果" />
    </ModalForm>
  );
};

export default HandleReport;
